﻿using Assets._Script.Entity.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets._Script.Entity.Character
{
    //玩家类
    public class Player
    {
        //当前等级的生命上限
        private int maxHp;

        public int MaxHp
        {
            get { return maxHp; }
            //生命上限是当前等级乘以100
            set { maxHp = this.level*100; }
        }

        //当前生命
        private int hp;

        public int Hp
        {
            get { return hp; }
            //通过封装赋值器，设定了赋值规则，当前生命不能大于生命上限
            set {
                if (value > this.maxHp) { 
                    throw new ArgumentOutOfRangeException("当前 生命值 不能超过生命上限！");
                }
                hp = value;
            }
        }

        //等级
        private int level;

        public int Level
        {
            get { return level; }
            //设定当前等级不能被赋值 <= 0 
            set {
                if (value <= 0)
                {
                    throw new ArgumentOutOfRangeException(" Level 等级 不能 <= 0 !!!");
                }
                level = value; 
            }
        }

        private Weapon _weapon;

        public Weapon Weapon
        {
            get { return _weapon; }
            set { _weapon = value; }
        }


        //全参构造方法
        public Player(int hp, int level)
        {
            this.Level = level;
            this.MaxHp = 1;
            this.Hp = hp;
        }

        public Player() { }

        //换枪
        //参数用来获取要更换的武器，必须使用父类对象名
        public void ChangeWeapon(Weapon weapon)
        {
            this.Weapon = weapon;
            Debug.Log($"玩家更换武器 \r\n{weapon.ToString()}");


        }

        //攻击
        public void Shoot() {
            this.Weapon.Attack();
        }
    }
}
